// 时间转换成描述
export function timeAgo(ts){
  if ((ts + '').length === 10) {
    ts = parseInt(ts) * 1000
  }
  const d = new Date(ts);
  const now = Date.now();
  const diff = (now - d) / 1000;
  if (diff < 60 * 10) {
    return '刚刚'
  } else if (diff < 3600) { // less 1 hour
    return Math.ceil(diff / 60) + '分钟前'
  } else if (diff < 3600 * 24) {
    return Math.ceil(diff / 3600) + '小时前'
  } else if (diff < 3600 * 24 * 30) {
    return Math.ceil(diff / 3600 /24) + '天前'
  } else if (diff < 3600 * 24 * 30 * 12) {
    return Math.ceil(diff / 3600 / 24 / 30) + '月前'
  } else {
    return Math.ceil(diff / 3600 / 24 / 30 / 12) + '年前'
  }
}

//时间长度 转换成字符串
export function timeDuration(duration){
  //分钟
  var minutes = parseInt(duration / 60);
  if (minutes < 10) {
    minutes = "0" + minutes;
  }
  //秒
  var seconds = parseInt(duration % 60);
  if (seconds < 10) {
    seconds = "0" + seconds;
  }
  return minutes + ":" + seconds;
}

//时间长度 转换成字符串
export function priceFormat(price) {
  if (isNaN(price)) {
    return price;
  }
  //分 --> 元
  var fprice = price / 100;
  return fprice.toFixed(2);
}
